package com.haoting.mamba.player.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.haoting.mamba.player.entity.PlayerInformationEntity;
import com.haoting.mamba.player.entity.vo.PlayerBasicdateEntityVo;
import com.haoting.mamba.player.entity.vo.SortByVo;
import com.haoting.mamba.player.service.PlayerInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haoting.common.utils.PageUtils;
import com.haoting.common.utils.Query;

import com.haoting.mamba.player.dao.PlayerBasicdateDao;
import com.haoting.mamba.player.entity.PlayerBasicdateEntity;
import com.haoting.mamba.player.service.PlayerBasicdateService;


@Service("playerBasicdateService")
public class PlayerBasicdateServiceImpl extends ServiceImpl<PlayerBasicdateDao, PlayerBasicdateEntity> implements PlayerBasicdateService {

    @Override
    public List<SortByVo> getSortbyVO(String sortvo) {
        return baseMapper.getSortbyVO(sortvo);
    }

    @Autowired
    PlayerInformationService playerInformationService;

    @Override
    public Page<PlayerBasicdateEntityVo> getbasicVo(Page<PlayerBasicdateEntityVo> basicdateEntityVoPage) {
        return baseMapper.getbasicVo(basicdateEntityVoPage);
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<PlayerBasicdateEntity> wrapper =  new QueryWrapper<>();
        if(!String.valueOf(params.get("query")).equals("")){
            wrapper.eq("stage",params.get("query"));
        }
        if(!String.valueOf(params.get("key")).equals("")){
            PlayerInformationEntity one = playerInformationService.getOne(new QueryWrapper<PlayerInformationEntity>()
                    .like("name", params.get("key")));
            String playerId = one.getId();
            wrapper.like("player_id",playerId);
        }
        IPage<PlayerBasicdateEntity> page = this.page(
                new Query<PlayerBasicdateEntity>().getPage(params),
                wrapper
        );

        for (int i=0;i<page.getRecords().size();i++){
            PlayerInformationEntity byId = playerInformationService.getById(page.getRecords().get(i).getPlayerId());
            String name = byId.getName();
            page.getRecords().get(i).setPlayerId(name);
        }
        return new PageUtils(page);
    }


}